package com.zzh.wsss.service.impl;

import com.zzh.wsss.mapper.AdminOperateMapper;
import com.zzh.wsss.pojo.Admin;
import com.zzh.wsss.pojo.User;
import com.zzh.wsss.service.AdminLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AdminLoginServiceImpl implements AdminLoginService {

    @Autowired
    private AdminOperateMapper adminOperateMapper;

    @Override
    public Boolean adminlogin(String username, String password) {
        List<Admin> list=adminOperateMapper.getPassword(username);
        if(list.size()==0)return false;
        Admin admin=list.get(0);
        if(admin.getAdminPassword().equals(password)){
            return true;
        }
        else return false;
    }

    @Override
    public Admin adminloginmsg(String username) {
        return adminOperateMapper.getAdminMag(username);
    }

    @Override
    public Boolean updatapassword(String username, String oldpassword, String newpassword) {
        List<Admin> list=adminOperateMapper.getPassword(username);
        if(list.size()==0)return false;
        Admin admin=list.get(0);
        if(admin.getAdminPassword().equals(oldpassword)){
            adminOperateMapper.SetUserPassword(username,newpassword);
            return true;
        }else return false;
    }
}
